<?php
/*------------------------------------------------------------------------
# com_vportfolio - Vportfolio component
# ------------------------------------------------------------------------
# author    Vsmart Extensions
# copyright Copyright (C) 2010 www.vsmart-extensions.com. All Rights Reserved.
# @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
# Websites: http://www.vsmart-extensions.com
# Technical Support:  Forum - http://www.vsmart-extensions.com
-------------------------------------------------------------------------*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.application.component.model' );

/**
 * @package Joomla
 * @subpackage Config
 */
class vportfolioConfigComponentModel extends JModel
{
	/** @var object JTable object */
	var $_table = '#__vportfolio_config';

	/**
	 * Returns the internal table object
	 * @return JTable
	 */
	function &getTable()
	{
		if ($this->_table == null) {
			$this->_table = JTable::getInstance('component', $this->getDBO() );
		}
		return $this->_table;
	}

	/**
	 * Get the params for the configuration variables
	 */
	function &getConfig(){
	
		$db 		=& JFactory::getDBO();
		
		$query = 'SELECT * FROM #__vportfolio_config order by id';
		$db->setQuery($query);
		$rows = $db->loadObjectList();

		return $rows;
	}
	function &getConfigParams(){
	
		$rows = $this->getConfig();
		
		$config->cf_url = $rows[0]->value;
		$config->cf_review = $rows[1]->value;
		$config->cf_extra = $rows[2]->value;
		$config->cf_cb = $rows[3]->value;
		$config->cf_allow_review = $rows[4]->value;
		$config->cf_allow_rating = $rows[5]->value;
		$config->cf_type = $rows[6]->value;
		$config->cf_heading = $rows[7]->value;
		$config->cf_category_des = $rows[8]->value;
		$config->cf_contact_link = $rows[9]->value;
		$config->cf_allow_review_auto = $rows[10]->value;
		$config->cf_click_to_thumb_image = $rows[11]->value;
		return $config;
	}
	function &saveConfig(){
		
		//Get post data
		$option = array();
		
		$option[0] = JRequest::getVar('cf_url',0);
		if($option[0] != 1) $option[0] = 0;
		
		$option[1] = JRequest::getVar('cf_review',0);
		if($option[1] != 1) $option[1] = 0;
		
		$option[2] = JRequest::getVar('cf_extra',0);
		if($option[2] != 1) $option[2] = 0;
		
		$option[3] = JRequest::getVar('cf_cb',0);
		if($option[3] != 1) $option[3] = 0;
		
		$option[4] = JRequest::getVar('cf_allow_review',0);
		if($option[4] != 1) $option[4] = 0;
		
		$option[5] = JRequest::getVar('cf_allow_rating',0);
		if($option[5] != 1) $option[5] = 0;
		
		$option[6] = JRequest::getVar('cf_type','');
		$option[6] = mysql_escape_string($option[6]);
		
		$option[7] = JRequest::getVar('cf_heading','');
		$option[7] = mysql_escape_string($option[7]);
		
		$option[8] = JRequest::getVar('cf_category_des',0);
		if($option[8] != 1) $option[8] = 0;
		
		$option[9] = JRequest::getVar('cf_contact_link','');
		
		$option[10] = JRequest::getVar('cf_allow_review_auto',0);
		if($option[10] != 1) $option[10] = 0;
		
		$option[11] = JRequest::getVar('cf_click_to_thumb_image',0);
		if($option[11] != 1) $option[11] = 0;
		
		
		$db 		=& JFactory::getDBO();
		
		for($i=0;$i<sizeof($option);$i++){
			$query = "UPDATE #__vportfolio_config SET `value` = '".$option[$i]."' WHERE id = '".($i+1)."'";
			$db->setQuery($query);
			$db->query();
		}
		
	}
}
?>
